<template>
	<view>
		<form v-show="loading">
			<view class="kuang margin-sm padding-sm bg-white">
				<view class="text-orange">
					如果您在使用本平台过程中遇到问题Bug，或者有更好的意见建议，欢迎留言，感谢您对{{this.app.title}}的支持；
					此反馈不会马上回复，如果您遇到卡券处理问题，请联系右下角在线客服，以免耽误您的卡券处理进度。
				</view>
			</view>
			<view class="margin-sm radius">
				<view class="cu-form-group margin-top ">
					<view class="title">选择卡种</view>
					<picker @change="PickerChange" :value="index" range-key="title" :range="picker">
						<view class="picker">
							{{index>-1?picker[index].title:'请选择卡种'}}
						</view>
					</picker>
				</view>
				<view class="cu-form-group">
					<view class="title">反馈标题</view>
					<input placeholder="请输入标题(必填)" v-model="title"></input>
				</view>
				<view class="cu-form-group align-start">
					<view class="title">反馈内容</view>
					<textarea maxlength="-1" @input="textareaBInput" placeholder="请详细描述您的问题和建议(必填)"></textarea>
				</view>
				<view class="cu-form-group">
					<view class="title">联系方式</view>
					<input placeholder="请输入联系方式" v-model="contact"></input>
				</view>
			</view>
			<view class="padding flex flex-direction">
				<button class="cu-btn bg-green margin-tb-sm lg" @tap='subb'>提交反馈</button>
			</view>
		</form>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				index: -1,
				picker: [],
				title:null,
				textareaBValue:null,
				contact:null,
				loading:false,
				cardid:0
			}
		},
		onLoad() {
			uni.showLoading({
				mask:true
			})
			this.getCardlist()
		},
		methods: {
			PickerChange(e) {
				this.index = e.detail.value
				this.cardid=this.picker[this.index].id
			},
			textareaBInput(e) {
				this.textareaBValue = e.detail.value
			},
			subb(){
				if(this.cardid==0){
					this.app.showMsg("请选择卡类")
					return;
				}
				if(this.title==null){
					this.app.showMsg("请输入标题")
					return;
				}
				if(this.textareaBValue==null){
					this.app.showMsg("请输入反馈类容")
					return;
				}
				
				uni.showLoading({
					mask:true
				})
				var that=this
				uni.request({
					url: that.app.apiHost+"/feedback",
					method:'POST',
					header:{'Authorization':'bearer '+that.app.getAuthCode()},
					data:{type:that.cardid,title:that.title,content:that.textareaBValue,contact:that.contact},
					success:(res)=>{
						uni.hideLoading()
						console.log(res.data);
						if(res.data.code == -1){
							that.app.showMsg('请登陆后再操作!','../login/login');
						}
						if(res.data.code==0){
							that.app.showMsg('提交反馈成功','../my/my')
							setTimeout(() => {
								uni.switchTab({
									url: '/pages/my/my'
								})
							}, 1000)
						}else{
							that.app.showMsg(res.data.msg)
						}
					},
					fail(res) {
					}
				})
			},
			getCardlist(){
				var that=this;
				uni.request({
					url: that.app.apiHost+"/getcs",
					method:'POST',
					header:{'Authorization':''},
					success:(res)=>{
						uni.hideLoading()
						that.loading=true
						that.picker=res.data.data
						console.log(res.data);
					},
					fail(res) {
					}
				})
			}
		}
	}
</script>

<style>
	page{
		background-color: #f1f1f1;
	}
.kuang{
		border: #f60 dashed 1px;
		border-radius: 5px;
	}
</style>
